import { GetNewsDetail, SetTaskScore } from "@/api";

export const useContent = () => {
    const detail = ref({});
    const route = useRoute();
    const pageStore = usePageStore();

    const GetDetail = async () => {
        const res = await GetNewsDetail({ id: route.params.id });
        if (res.code == 200) {
            detail.value = res.data;
        } else {
            if (!pageStore.isMobile) {
                throw createError({
                    statusCode: 404,
                    statusMessage: "页面未找到",
                });
            } else {
                Message().error(res.msg);
            }
        }
    };

    onMounted(async () => {
        await nextTick();

        setTimeout(() => {
            SetTaskScore({
                code: 1001,
                _id: route.params.id,
            });
        });
    });

    return {
        detail,
        GetDetail,
    };
};
